
//渲染桌子
function readerTable(seatNumber,id,menu){
    //首先判断点菜的规则是否满足校验的规则
    if(menuCanUser()==true){
        //点餐完成后，将东西清理掉
        finishOrder(seatNumber,id);
        //修改桌子的颜色和菜品的颜色
        let tableID = judgeTable(seatNumber);
        //获取div里面的第一个div的顾客栏
        let parentFirst = $(tableID).firstChild;
        //获取div里面的最后一个div菜单栏
        let parentLast = $(tableID).lastChild;
        let foodDiv = parentLast.childNodes;//获取food里面的菜单的信息
        //先把东西的成本价进行扣除
        let originPrice =0
        for(let j in foodDiv){
            if((typeof foodDiv[j] ==="object")){
                let foodName = foodDiv[j].innerHTML;
                originPrice += countFoodOrign(foodName);
            }
        }
        console.log(originPrice);
        let totalIncome = $("all_momey");
        let totalIncomeInt = parseInt(totalIncome.innerHTML);
        totalIncomeInt -=parseInt(originPrice);
        totalIncome.innerHTML =""+ totalIncomeInt;
        //设置其eating的进度条
        let background ="background: linear-gradient(-90deg, #" + color[seatNumber].color1 + " 50%, #" + color[seatNumber].color2 + " 50%);";
        //设置用户的桌子上面对应用户的背景的颜色
        let backgroundColor = "background-color:#" + color[seatNumber].color2 + ";";
        parentFirst.setAttribute("style",background);//渲染桌子的颜色
        for(let j in foodDiv){
            if((typeof foodDiv[j] ==="object")){
                foodDiv[j].setAttribute("style",backgroundColor);//渲染菜品
                let firstColor =0;
                let secondColor = 100;
                let eatingFood = false;
                let background = "";
                let foodName = foodDiv[j].innerHTML;
                let foodPrice = countFoodPrice(foodName);
                let timer = setInterval(()=>{
                    firstColor += cusWaitingChange;
                    secondColor -= cusWaitingChange;
                    background = "background: linear-gradient(-90deg, #" + color[seatNumber].color2 + " " + secondColor + "%, #" + color[seatNumber].color1 + " " + "0,#" + color[seatNumber].color1 + " " + firstColor + "%)";
                    foodDiv[j].setAttribute("style",background);
                    //进入来之后先是在的是等待状态上面进行等待。
                    //加入对应所点的菜才出现在完成的列表里面则由等待的状态转变为吃饭的状态
                    //同时进入吃饭状态的开始计算时间
                    if(finishCookList.length > 0){
                        for(let k in finishCookList){
                            if(finishCookList[k].tableID === seatNumber){
                                let foodId = finishCookList[k].foodID;
                                //修改菜品对应的颜色
                                if(foodDiv[j].innerHTML === dishes[foodId].name){
                                    secondColor =0;
                                    firstColor =100;
                                    eatingFood = true;//说明顾客进入吃饭的判断
                                    //重新开始计算吃饭的时间
                                    eatFood(seatNumber,foodDiv[j],background,foodPrice);
                                    finishCookList.shift();//在完成的列表里面删除这一道菜
                                    clearInterval(timer);

                                }

                            }
                        }
                    }
                    //假如是等菜的时间已经到，但是菜依旧是没有上的，则说明其心态崩了，准备走人
                    //假如其他菜已经上，但是其他的菜的等待时间到了，则则会支付已经吃完的菜的钱，其他的不会支付
                    //在其相对应的餐桌上面添加一个小爱心
                    if(eatingFood ===false && secondColor <=0){
                        //等待时间已到
                        clearInterval(timer);
                        table[seatNumber].dealCount +=1;
                        getMoney(seatNumber);
                        foodDiv[j].setAttribute("style","text-decoration:line-through;background-color:#505060;")
                    }
                },cusWaitingTime / 10)
                

            }else{
                break;
            }
        }
        getFoodList(seatNumber);//生成厨房菜单
        handerKitchen();//开始厨房操作
        let renderText = customer[id].name+"完成点餐，等候用餐\n疯狂点击厨师的头像可以加速做菜";
        ElMessage("remind",renderText,2000);
        menu.style.display ="none";
    }
}
//判断是桌子
function judgeTable(seatNumber){
    //首先判断哪一个桌子是空余的，然后把这个顾客安装到这个桌子上
    switch(seatNumber){
        case "0":
            return "table-firstRow-left";
        case "1":
            return "table-firstRow-right";
        case "2":
            return "table-secondRow-left";
        case "3":
            return "table-secondRow-right";
    }
    return null;
}
//清理桌子
function cleanTable(seatNumber){
    let tableID = judgeTable(seatNumber);
    let ele = $(tableID);
    let renderHtml ="<div></div>"
    ele.innerHTML = renderHtml;
    table[seatNumber]={//将桌子参数的残留值进行修改
        list:[],
        total:[],
        canUse:true,
        userID:0,
        money:0,
        dealCount:0
    };
    if(eatingNumber > 0){
        eatingNumber--;//同时使用的桌子的减少一
    }
    return;
}
